<script setup lang="ts">
import { useAuthRole } from './hook'

import { useTableHeight } from '@/hooks/useTableHeight'
import { watch } from 'vue'
defineOptions({
  name: 'AuthRole',
})

const {
  form,
  roleRef,
  loading,
  columns,
  dataList,
  pagination,
  showSelection,
  cancel,
  clickRow,
  getRowKey,
  submitForm,
  handleSizeChange,
  handleCurrentChange,
  handleSelectionChange,
} = useAuthRole()
const { tableHeight, tableRef } = useTableHeight()

watch(
  () => roleRef.value,
  (val) => {
    roleRef.value = val
    tableRef.value = val
  }
)
</script>

<template>
  <div class="main table-view-layout">
    <el-form ref="formRef" :inline="true" :model="form" class="bg-el-bg w-[99/100] pl-8 pt-4">
      <el-row>
        <el-col :span="8" :offset="2">
          <el-form-item label="用户昵称" prop="nickName">
            <el-input v-model="form.nickName" disabled />
          </el-form-item>
        </el-col>
        <el-col :span="8" :offset="2">
          <el-form-item label="登录账号" prop="userName">
            <el-input v-model="form.userName" disabled />
          </el-form-item>
        </el-col>
      </el-row>
    </el-form>
    <PureTableBar title="角色信息">
      <template #buttons>
        <el-button type="primary" @click="submitForm"> 提交 </el-button>
        <el-button type="info" @click="cancel">返回</el-button>
      </template>
      <template #table>
        <pure-table
          ref="roleRef"
          border
          align-whole="center"
          showOverflowTooltip
          table-layout="auto"
          :row-key="getRowKey"
          :loading="loading"
          :max-height="tableHeight"
          :checkList="showSelection ? ['勾选列'] : []"
          :data="dataList"
          :columns="columns"
          :pagination="pagination"
          :header-cell-style="{
            background: 'var(--el-table-row-hover-bg-color)',
            color: 'var(--el-text-color-primary)',
          }"
          @row-click="clickRow"
          @selection-change="handleSelectionChange"
          @page-size-change="handleSizeChange"
          @page-current-change="handleCurrentChange"
        />
      </template>
    </PureTableBar>
  </div>
</template>

<style scoped lang="scss">
:deep(.el-dropdown-menu__item i) {
  margin: 0;
}
</style>
